package tuiLayer;
import java.util.Scanner;
import controlLayer.*;
import modelLayer.*;


/**
 * Write a description of class MainUI here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MainUI{
    SaleUI saleUI;
    CustomerUI customerUI;
    StaffUI staffUI;
    ItemUI itemUI;
    String errorMessage = "Incorrect command!";
    private String message="";
    Scanner keyboard = new Scanner(System.in);
    
    ItemController itemController = new ItemController();
    Customer customer = new RegularCustomer("Johnny", "acasa", "000", 12, false, 10);
    Item i = new NormalItem("Table", 100, 1, 3, "DIY");
    Item i1 = new NormalItem("Chair", 70, 2,1, "Home");
    ItemContainer items = ItemContainer.getInstance();
    Staff s = new Staff("Janis", "2", 23, "Janis", "4", false);
    StaffContainer staffs = StaffContainer.getInstance();
    Item set = new Set("Kitchen", 150, 99);
    CustomerContainer customerContainer = CustomerContainer.getInstance();
    
    public MainUI(){
        items.addNormalItem(i);
        items.addNormalItem(i1);
        staffs.addStaff(s);
        ((Set)set).addSetItem(itemController.findItem(1).getBarcode());
        ((Set)set).addSetItem(itemController.findItem(2).getBarcode());
        int qu=itemController.makeSetQuantity(set.getBarcode(),set);
        set.setQuantity(qu);
        items.addSet(set);
        customerContainer.addCustomer(customer);
        
        writeMainMenu();
    }
    
    public void writeMainMenu(){System.out.println("\f***Start sale Menu***");
        System.out.println(" (1) SaleUI");
        System.out.println(" (2) CustomerUI");
        System.out.println(" (3) StaffUI");
        System.out.println( " (4) ItemUI");
        System.out.println(" (5) Quit");        
    	System.out.println("To make testing easier: \nCustomer id: 12\nStaff username: Janis\nItem1 barcode: 1\nItem2 barcode: 2\nSet barcode: 99\n");
        
        String choice = getString();
        
        switch(choice){
            case "1":
               saleUI = new SaleUI();
               saleUI.writeSaleMenu();
               break;
            case "2":
                customerUI = new CustomerUI();
                customerUI.writeCustomerMenu();
                break;
            case "3":
                staffUI = new StaffUI();
                staffUI.writeStaffMenu();
                break;
            case "4":
            	itemUI=new ItemUI();
            	itemUI.writeItemMenu();
            case "5":
                quit();
                break;
            default:
                System.out.println(errorMessage);
                pressEnter();
                writeMainMenu();
        }
    }
    private void pressEnter(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("Press enter to continue.");
        scanner.nextLine(); 
    }
    private String getString(){
        String startChoice ;
        startChoice = keyboard.nextLine();
        String choice = startChoice.trim().toLowerCase();
        return choice;
    }
    private void quit(){
        System.out.println("Have a nice day! Good bye!");
        System.exit(0);
    }
}